package cn.luowb.checkchat.dao.mapper;

import cn.luowb.checkchat.dao.entity.CommentDO;
import cn.luowb.checkchat.dto.req.CommentPageDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author heimenkyou
 * @description 针对表【comment(评论)】的数据库操作Mapper
 * @createDate 2025-09-01 19:07:09
 * @Entity cn.luowb.checkchat.dao.entity.CommentDO
 */
public interface CommentMapper extends BaseMapper<CommentDO> {
    @Select("select * from comment where post_id=#{postId} and create_time<=#{lastTime} and pid is null order by create_time desc limit #{offset},#{size}")
    List<CommentDO> pageQuery(CommentPageDTO commentPageDTO);

    @MapKey("commentId")
    List<Map<String, Long>> countReplyCount(List<Long> commentIds);

    @Select("select * from comment where pid=#{commentId} and create_time<=#{lastTime}  order by create_time desc limit #{offset},#{size}")
    List<CommentDO> replyPageQuery(CommentPageDTO commentPageDTO);

    /**
     * 增加点赞数
     */
    @Update("UPDATE comment SET like_count = like_count + #{delta} WHERE id = #{id}")
    void incrementLikeCount(long id, int delta);
}




